package com.example.mapper;

import com.example.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //根据用户名查询用户
    //@Select("select * from user where username=#{username}")
    User findByUsername(String username);

    @Insert("insert into user(username,password,create_time,update_time)" +
            "values (#{username},#{password},now(),now())")
    void add(String username, String password);

    void addNew(User user);

    //@Update("update user set nickname=#{nickname},email=#{email},update_time=#{updateTime},address=#{address},mobile=#{mobile} where id = #{id}")
    void update(User user);

    //@Update("update user set user_pic=#{avatarUrl},update_time = now() where id = #{id}")
    void updateAvatar(String avatarUrl, Integer id);

    //@Update("update user set password=#{md5String},update_time = now() where id = #{id}")
    void updatePwd(String md5String, Integer id);

    @Select("select * from user where phone = #{phone}")
    User findByPhone(String phone);

    List<User> search(String username, Integer id, String phone, Integer role);

    @Delete("delete from user where id = #{id}")
    void delete(Integer id);
    @Update("update user set status = 1 where id = #{id}")
    void disable(Integer id);
    @Select("select * from user")
    List<User> list();

    @Select("select * from user where id = #{id}")
    User findById(Integer id);
}
